package com.ganmiao.web.supplier.controller.sys;

import com.ganmiao.resp.CommonResultRes;
import com.ganmiao.resp.MobBaseRes;
import com.ganmiao.resp.PageResult;
import com.ganmiao.resp.ResponseCode;
import com.ganmiao.server.sys.entity.SysUserRole;
import com.ganmiao.server.sys.query.SysUserRoleQuery;
import com.ganmiao.server.sys.service.SysUserRoleService;
import com.ganmiao.server.sys.validated.Add;
import com.ganmiao.server.sys.validated.Delete;
import com.ganmiao.server.sys.vo.SysUserRoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户角色信息
 */
@Api(tags = "用户角色信息")
@Slf4j
@RestController
@RequestMapping("/sysUserRole")
public class SysUserRoleController {

    //用户角色信息
    @Autowired
    private SysUserRoleService sysUserRoleService;

    /**
     * 新增用户角色信息 (关联用户)
     *
     * @param sysUserRole
     * @return
     */
    @ApiOperation("新增用户角色信息 (关联用户)")
    @PostMapping("/addSysUserRole")
    public MobBaseRes addSysUserRole(@RequestBody @Validated(Add.class) SysUserRole sysUserRole) {
        return sysUserRoleService.addSysUserRole(sysUserRole) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "关联成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "关联失败");
    }

    /**
     * 删除用户角色信息 (取消授权)
     *
     * @param sysUserRole
     * @return
     */
    @ApiOperation("删除用户角色信息 (取消授权)")
    @PutMapping("/deleteSysUserRole")
    public MobBaseRes deleteSysUserRole(@RequestBody @Validated(Delete.class) SysUserRole sysUserRole) {
        return sysUserRoleService.deleteSysUserRole(sysUserRole) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "取消授权成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "取消授权失败");
    }

    /**
     * 获取用户角色信息 (关联用户/取消授权)
     *
     * @param sysUserRoleQuery
     * @return
     */
    @ApiOperation("获取角色信息 (分页)")
    @GetMapping("/getSysUserRoleList")
    public CommonResultRes<PageResult<SysUserRoleVo>> getSysUserRoleList(SysUserRoleQuery sysUserRoleQuery) {
        return new CommonResultRes<>(sysUserRoleService.getSysUserRoleList(sysUserRoleQuery));
    }

}
